/*
 * @Author: 汁源 lzy21145@sina.com
 * @Date: 2025-05-06 14:38:50
 * @LastEditors: 汁源 lzy21145@sina.com
 * @LastEditTime: 2025-05-07 17:29:33
 * @FilePath: /vue-comp-demo/internal/vite.config.full.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { resolve } from 'path';
import vue from '@vitejs/plugin-vue';
import { defineConfig } from 'vite';
import AutoImport from 'unplugin-auto-import/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import Components from 'unplugin-vue-components/vite';
import { packages, root } from './pathname';
import dts from 'vite-plugin-dts';

export default defineConfig({
    plugins: [
        vue(),
        AutoImport({
            imports: ['vue'],
            resolvers: [ElementPlusResolver()],
            dts: resolve(packages, 'components/auto-import.d.ts'),
        }),
        Components({
            resolvers: [ElementPlusResolver()],
            dts: resolve(packages, 'components/components.d.ts'),
        }),
        dts({
            outDir: resolve(packages, 'components/dist/types'),
            copyDtsFiles: true,
            tsconfigPath: resolve(root, 'tsconfig.web.json'),
            include: ['../packages/components/**/*', '../packages/hooks/**/*'],
            exclude: ["../**/node_modules", "../**/dist", "**/*.md"]
        }),
    ],
    build: {
        lib: {
            entry: resolve(root, 'packages/components/index.ts'),
            name: 'lzy-components',
            formats: ['umd'],
            fileName: (format) => `lzy-components.${format}.js`,
        },
        rollupOptions: {
            external: ['vue'],
            output: {
                dir: resolve(packages, 'components/dist'),
                globals: {
                    vue: 'Vue',
                },
                exports: 'named',
                assetFileNames: 'styles.css',
            },
        },
        sourcemap: true,
        emptyOutDir: true,
        cssCodeSplit: false,
    },
    esbuild: {
        drop: ['console', 'debugger'],
    },
});